package name.marz.to.go.ahg.mhbk.executer;

import name.marz.to.go.ahg.core.checker.Checker;
import name.marz.to.go.ahg.core.exception.UserProcessException;
import name.marz.to.go.ahg.mhbk.exception.WrongAnswerException;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class MHBKSecretQAChecker implements Checker<Document> {
	@Override
	public void check(Document target) throws UserProcessException {
		checkStr(target,"合言葉が間違っています");
		checkStr(target,"合言葉に入力できない文字が混在しています");
	}
	
	private void checkStr(Document doc,String s) throws UserProcessException {
		Elements elems = doc.getElementsContainingOwnText(s);
		if ( elems.size() == 0 ) return;
		StringBuffer sb = new StringBuffer();
		for (Element e : elems) {
			sb.append(e.text());
		}
		throw new WrongAnswerException(sb.toString());
	}
}